/*
 * PolizIterator.cpp
 *
 *  Created on: 15.04.2012
 *      Author: Eugene Kornykhin
 */

#include "Poliz.h"
#include "PolizIterator.h"
#include <stdexcept>
#include <iostream>
using namespace std;

PolizIterator::PolizIterator(Poliz &poliz, PolizPosition pos)
: poliz(poliz), position(pos) {

}


PolizIterator::PolizIterator(const Poliz &poliz, PolizPosition pos)
: poliz(poliz), position(pos) {

}


PolizIterator::~PolizIterator() {
}

PolizIterator& PolizIterator::operator ++() {
	position = position.next();
	return *this;
}

PolizIterator & PolizIterator::operator =(const PolizIterator & iterator)
{
	// it is private!
	return *this;
}

PElement &PolizIterator::operator *() const
{
	if (position.getPosition() >= poliz.numberOfElements()) {
		throw out_of_range("Access to iterator out of range");
	}
	return poliz.getElement(position.getPosition());
}

void PolizIterator::moveto(PolizPosition destination)
{
	position = destination;
}

PolizPosition PolizIterator::getPosition() const
{
	return position;
}
